<?php

namespace App\Console\Commands;

use App\Models\GoodsOrder;
use Carbon\Carbon;
use Illuminate\Console\Command;

class ShopOrderCompleteCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'shoporder:complete';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '商品订单自动完成';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $now = Carbon::now();
        $goodsOrderList = GoodsOrder::where('order_status', '=', GoodsOrder::ORDER_NOT_RECEIVED)->where('complete_time', '<=', $now)->get();
        foreach ($goodsOrderList as $goodsOrder){
            GoodsOrder::complete($goodsOrder);
        }
    }









}
